<?php

/**
 * informes actions.
 *
 * @package    plagas
 * @subpackage informes
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class informesActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeIndex(sfWebRequest $request)
  {
    $this->filter = new informesFormFilter();
    $this->datos = null;
  }

  public function executeFilter(sfWebRequest $request)
  {
     $this->getUser()->setFlash('error', null);
     $this->filter = new informesFormFilter();
     if($request->isMethod('post'))
     {
        $this->filter->bind($request->getParameter($this->filter->getName()));
     }
     $allFormValues = $request->getParameter($this->filter->getName());
     $indicador = $allFormValues["indicador_id"];
     $ano = $allFormValues["ano"]["text"];
     $mes = $allFormValues["mes"]["text"];

     $reales = Doctrine_Core::getTable('reales')->getLast13Reales($indicador,$mes,$ano);
     if ($reales->count() == 0)
     {
        $this->getUser()->setFlash('error', 'No se encontraron resultados para la seleccion realizada.');
     }
     $this->datos = '';
     $this->cantidad = 0;
     $this->dominio = '';
     foreach ($reales as $real)
     {
         $this->datos .= ($real->getValor() * 100).',';
         $this->cantidad++;
         $this->dominio .='|'.$real->getMes().'/'.$real->getAno();
     }
     $this->datos = substr ($this->datos, 0, strlen($this->datos) - 1);
     $this->titulo = $reales[0]->getIndicador()->getNombre();
     $this->setTemplate('index');
  }
}
